package com.xiao.provider.service.impl;

import com.xiao.common.utils.IDUtli;
import com.xiao.provider.dao.UserDao;
import com.xiao.provider.entity.User;
import com.xiao.provider.service.UserService;
import com.xiao.provider.vo.reqvo.UserReqVo;
import com.xiao.provider.vo.resvo.UserResVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * @Description 用户service层接口实现类
 * @Auther: 笑笑是一个码农
 * @Date: 16:05 2020/12/22
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    public void insert(UserReqVo userReqVo) {
        User user = new User();
        BeanUtils.copyProperties(userReqVo, user);
        user.setId(IDUtli.nextId());
        userDao.insert(user);
    }

    @Override
    public UserResVo selectById(Long id) {
        User user = userDao.selectById(id);
        if (user == null)
            return null; //  fixme 需要抛出异常告知调用者未查询到用户，等待全局异常处理完成后修复
        return user.toResVo(user);
    }

    @Override
    public void update(Long id, UserReqVo userReqVo) {
        User user = new User();
        BeanUtils.copyProperties(userReqVo, user);
        user.setId(id);
        userDao.update(user);
    }

    @Override
    public void delete(Long id) {
       userDao.delete(id);
    }
}
